home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-20  |  8.5 KB  |  315 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file is where you place various definitions and constant values for
  20. ** DTS.Lib..framework's use.  You will also add some code within the two
  21. ** functions to handle the various document types. */
  22.  
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28.  
  29. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  30. #include "App.defs.h"        /* Get various application definitions.            */
  31. #include "App.protos.h"        /* Get the prototypes for application.            */
  32.  
  33. #ifndef __ERRORS__
  34. #include <Errors.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /* In this file, we first set some global values.  This allows the application and
  44. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  45.  
  46.  
  47. short        gTypeListLen = 1;
  48. SFTypeList    gTypeList = {kDocFileType};
  49.     /* Here we declare the various document types that DTS.Draw can support.
  50.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  51.  
  52.  
  53.  
  54. /* Some DTS.Lib..framework gTypeList usage notes:
  55. **
  56. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  57. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  58. **     The index at which the match is found (+1) is used as the string number in the
  59. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  60. **     resource, then the last string is used.
  61. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  62. **     can be selected. */
  63.  
  64.  
  65.  
  66. #ifdef powerc
  67. #pragma options align=mac68k
  68. #endif
  69. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  70.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  71.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  72.     TheDoc            doc;            /* will place on the end of each.                            */
  73. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  74. #ifdef powerc
  75. #pragma options align=reset
  76. #endif
  77.  
  78.  
  79.  
  80. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  81. ** application.  The first 16 are reserved for the framework.  Our application-specific
  82. ** objects start at 16. */
  83.  
  84. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  85. /* 1  */                                         TRootObj,
  86. /* 2  */                                         TUndoObj,
  87. /* 3  */                                         TUndoTaskObj,
  88. /* 4  */                                         TUndoPartObj,
  89. /* 5  */                                         nil,
  90. /* 6  */                                         nil,
  91. /* 7  */                                         nil,
  92. /* 8  */                                         nil,
  93. /* 9  */                                         nil,
  94. /* 10 */                                         nil,
  95. /* 11 */                                         nil,
  96. /* 12 */                                         nil,
  97. /* 13 */                                         nil,
  98. /* 14 */                                         nil,
  99. /* 15 */                                         nil,
  100. /* 16        Start of app-specific procs. */         TRectObj,
  101. /* 17 */                                         TRRectObj,
  102. /* 18 */                                         TOvalObj,
  103. /* 19 */                                         TPieObj,
  104. /* 20 */                                         TLineObj,
  105. /* 21 */                                         nil,        /* Reserve space for other   */
  106. /* 22 */                                         nil,        /* objects that may be added */
  107. /* 23 */                                         nil,        /* to the tool palette.      */
  108. /* 24 */                                         nil,        /* The group object is never */
  109. /* 25 */                                         nil,        /* going to be in the tool   */
  110. /* 26 */                                         nil,        /* palette, so put it far    */
  111. /* 27 */                                         nil,        /* enough away to leave room */
  112. /* 28 */                                         nil,        /* for other objects.        */
  113. /* 29 */                                         nil,
  114. /* 30 */                                         nil,
  115. /* 31 */                                         nil,
  116. /* 32 */                                         nil,
  117. /* 33 */                                         nil,
  118. /* 34 */                                         nil,
  119. /* 35 */                                         nil,
  120. /* 36 */                                         nil,
  121. /* 37 */                                         nil,
  122. /* 38 */                                         nil,
  123. /* 39 */                                         nil,
  124. /* 40 */                                         nil,
  125. /* 41 */                                         nil,
  126. /* 42 */                                         nil,
  127. /* 43 */                                         nil,
  128. /* 44 */                                         nil,
  129. /* 45 */                                         nil,
  130. /* 46 */                                         nil,
  131. /* 47 */                                         nil,
  132. /* 48 */                                         nil,
  133. /* 49 */                                         nil,
  134. /* 50 */                                         nil,
  135. /* 51 */                                         nil,
  136. /* 52 */                                         nil,
  137. /* 53 */                                         nil,
  138. /* 54 */                                         nil,
  139. /* 55 */                                         nil,
  140. /* 56 */                                         nil,
  141. /* 57 */                                         nil,
  142. /* 58 */                                         nil,
  143. /* 59 */                                         nil,
  144. /* 60 */                                         nil,
  145. /* 61 */                                         nil,
  146. /* 62 */                                         nil,
  147. /* 63 */                                         nil,
  148. /* 64 */                                         nil,
  149. /* 65 */                                         TGroupObj,
  150. /* 66 */                                         TExtSelectObj};
  151.  
  152.  
  153.  
  154. /* The framework needs to know the minimum object sizes.  This table is used by the
  155. ** framework to make sure that the object is created at least minimally. */
  156.  
  157. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  158. /* 1  */                                         sizeof(RootObj),
  159. /* 2  */                                         sizeof(UndoObj),
  160. /* 3  */                                         sizeof(UndoTaskObj),
  161. /* 4  */                                         sizeof(UndoPartObj),
  162. /* 5  */                                         0,
  163. /* 6  */                                         0,
  164. /* 7  */                                         0,
  165. /* 8  */                                         0,
  166. /* 9  */                                         0,
  167. /* 10 */                                         0,
  168. /* 11 */                                         0,
  169. /* 12 */                                         0,
  170. /* 13 */                                         0,
  171. /* 14 */                                         0,
  172. /* 15 */                                         0,
  173. /* 16        Start of app-specific sizes. */         sizeof(RectObj),
  174. /* 17 */                                         sizeof(RRectObj),
  175. /* 18 */                                         sizeof(OvalObj),
  176. /* 19 */                                         sizeof(PieObj),
  177. /* 20 */                                         sizeof(LineObj),
  178. /* 21 */                                         0,
  179. /* 22 */                                         0,
  180. /* 23 */                                         0,
  181. /* 24 */                                         0,
  182. /* 25 */                                         0,
  183. /* 26 */                                         0,
  184. /* 27 */                                         0,
  185. /* 28 */                                         0,
  186. /* 29 */                                         0,
  187. /* 30 */                                         0,
  188. /* 31 */                                         0,
  189. /* 32 */                                         0,
  190. /* 33 */                                         0,
  191. /* 34 */                                         0,
  192. /* 35 */                                         0,
  193. /* 36 */                                         0,
  194. /* 37 */                                         0,
  195. /* 38 */                                         0,
  196. /* 39 */                                         0,
  197. /* 40 */                                         0,
  198. /* 41 */                                         0,
  199. /* 42 */                                         0,
  200. /* 43 */                                         0,
  201. /* 44 */                                         0,
  202. /* 45 */                                         0,
  203. /* 46 */                                         0,
  204. /* 47 */                                         0,
  205. /* 48 */                                         0,
  206. /* 49 */                                         0,
  207. /* 50 */                                         0,
  208. /* 51 */                                         0,
  209. /* 52 */                                         0,
  210. /* 53 */                                         0,
  211. /* 54 */                                         0,
  212. /* 55 */                                         0,
  213. /* 56 */                                         0,
  214. /* 57 */                                         0,
  215. /* 58 */                                         0,
  216. /* 59 */                                         0,
  217. /* 60 */                                         0,
  218. /* 61 */                                         0,
  219. /* 62 */                                         0,
  220. /* 63 */                                         0,
  221. /* 64 */                                         0,
  222. /* 65 */                                         sizeof(GroupObj),
  223. /* 66 */                                         sizeof(ExtSelectObj)};
  224.  
  225.  
  226.  
  227. /*****************************************************************************/
  228. /*****************************************************************************/
  229.  
  230.  
  231.  
  232. /* •• Called by DTS.Lib..framework. •• */
  233.  
  234. /* Do any additional document initialization here.  All fields not specifically set
  235. ** are already initialized to 0. */
  236.  
  237. #pragma segment File
  238. OSErr    InitDocument(FileRecHndl frHndl)
  239. {
  240.     OSErr    err;
  241.  
  242.     err = noErr;
  243.  
  244.     switch ((*frHndl)->fileState.sfType) {
  245.         case kDocFileType:
  246.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  247.             if (!err) {
  248.                 (*frHndl)->d.doc.fhInfo.hDocSize = (7 * 72);
  249.                 (*frHndl)->d.doc.fhInfo.vDocSize = (10 * 72);
  250.             }
  251.             break;
  252.         case kClipboardFileType:
  253.             ClipboardInitDocument(frHndl);
  254.             break;
  255.         case kToolFileType:
  256.             ToolInitDocument(frHndl);
  257.             break;
  258.         case 'PENS':
  259.             (*frHndl)->fileState.initContentProc = PENSInitContent;
  260.             (*frHndl)->fileState.freeWindowProc  = PENSFreeWindow;
  261.             break;
  262. #ifndef powerc
  263.         case '6hlp':
  264.             err = HelpInitDocument(frHndl);
  265.             break;
  266. #endif
  267. #if VH_VERSION
  268.         case kViewHierFileType:
  269.             return(VHInitDocument(frHndl));
  270.             break;
  271. #endif
  272.         default:
  273.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  274.             if (!err) {
  275.                 (*frHndl)->fileState.readDocumentProc  = nil;
  276.                 (*frHndl)->fileState.writeDocumentProc = nil;
  277.             }
  278.             break;
  279.     }
  280.  
  281.     return(err);
  282. }
  283.  
  284.  
  285.  
  286. /*****************************************************************************/
  287.  
  288.  
  289.  
  290. /* •• Called by DTS.Lib..framework. •• */
  291.  
  292. /* Return the initial size of the primary document handle, based on the OSType. */
  293.  
  294. #pragma segment File
  295. long    InitDocumentSize(OSType sftype)
  296. {
  297.     switch (sftype) {
  298.         case kDocFileType:
  299.         case kClipboardFileType:
  300.             return(sizeof(DocFileTypeRec));
  301.             break;
  302. #if VH_VERSION
  303.         case kViewHierFileType:
  304.             return(VHFileTypeSize());
  305.             break;
  306. #endif
  307.         default:
  308.             return(sizeof(DocFileTypeRec));
  309.             break;
  310.     }
  311. }
  312.  
  313.  
  314.  
  315.